package com.itheima.controller;

import com.itheima.domain.db.Questionnaire;
import com.itheima.domain.db.SoulQuestion;
import com.itheima.domain.db.SoulQuestionOption;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.ReportWebVo;
import com.itheima.domain.vo.SoulQuestionOptionWebVo;
import com.itheima.manager.SoulTestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class SoulTestController {
    @Autowired
    private SoulTestManager soulTestManager;

    //显示选项数据
    @GetMapping("/options")
    public PageBeanVo findOptionList(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "5") Integer pagesize) {
        return soulTestManager.findOptionList(page, pagesize);
    }

    //显示所有问题
    @GetMapping("/questionList")
    public List<SoulQuestion> findQuestionList() {
        return soulTestManager.findQuestionList();
    }

    //保存选项
    @PostMapping("/saveOption")
    public String saveOption(@RequestBody SoulQuestionOption soulQuestionOption) {

        return soulTestManager.saveOption(soulQuestionOption);
    }

    //删除选项
    @GetMapping("/deleteOptions")
    public String deleteOptions(Long id) {

        return soulTestManager.deleteOptions(id);
    }

    //回显选项
    @GetMapping("/showEditOption")
    public SoulQuestionOptionWebVo showEditOption(Long id) {

        return soulTestManager.showEditOption(id);
    }

    //修改选项
    @PostMapping("/updateOptions")
    public String updateOptions(@RequestBody SoulQuestionOption soulQuestionOption) {

        return soulTestManager.updateOptions(soulQuestionOption);
    }

    //显示报告列表
    @GetMapping("/report")
    public PageBeanVo report(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "5") Integer pagesize) {
        return soulTestManager.report(page, pagesize);

    }

    //添加报告
    @PostMapping("/saveReport")
    public String saveReport(@RequestBody ReportWebVo reportWebVo) {

        return soulTestManager.saveReport(reportWebVo);
    }


    //上传图片
    @PostMapping("/uploadReportInfo")
    public Map uploadReportInfo(MultipartFile file) throws IOException {

        return soulTestManager.uploadReportInfo(file);
    }


    //显示所有问卷
    @GetMapping("/questionnaireList")
    public List<Questionnaire> findQuestionnaireList() {
        return soulTestManager.findQuestionnaireList();
    }

    //删除报告
    @GetMapping("/deleteReport")
    public String deleteReport(Long id) {
        return soulTestManager.deleteReport(id);
    }

    //回显数据
    @DeleteMapping("/showEditReport")
    public ReportWebVo showEditReport(Long id) {
        return soulTestManager.showEditReport(id);
    }

    //修改报告
    @PostMapping("/updateReport")
    public String updateReport(@RequestBody ReportWebVo reportWebVo) throws IOException {

        return soulTestManager.updateReport(reportWebVo);
    }
}
